<%@ page language="java" import="java.util.List" pageEncoding="utf-8" %>
<%@page import="cn.com.wxd.entity.website.CatalogInfo" %>
<%@page import="cn.com.wxd.common.CharUtil" %>
<div>
    <script type="text/javascript">
        function addOrUpdateCata(cataid,isupdate) {
            var urlpath="admin/website/catalog/editCatalog?id="+cataid;
            if (!isupdate){
                urlpath="admin/website/catalog/addCatalog?parentId="+cataid;
            }
            parent.parentLayer.open({
                type: 2,
                maxmin: true, //开启最大化最小化按钮
                area: ['893px', $(window).height()+"px"],
                content: [urlpath],
                btn: ['修改','取消'],
                yes: function(index, layero){
                    $(layero).find("iframe")[0].contentWindow.ajaxSubSubmitForm(index);
                }
//                ,btn2:function (index) {
//                    if(confirm('确定放弃修改吗')){
//                        parent.parentLayer.close(index)
//                    }
//                    return false;
//               },
//                cancel: function(index){
//                    if(confirm('确定放弃修改吗')){
//                        parent.parentLayer.close(index)
//                    }
//                    return false;
//                }
            });
        }
        function deleteCatalog(id) {
            layer.confirm('你确定要删除吗?', {
                btn: ['确定','取消'], //按钮
                yes:function() {
                    $.ajax({
                        type: "get",
                        url: "admin/website/catalog/deleteCatalog",
                        data: {"id": id},
                        success: function (result) {
                            if (result.success) {
                                OutMessageBox("删除成功,请刷新页签!", 3000);
                                FListajax("${parentId}");	 //刷新
                            } else if (result.errNo = -1) {
                                jAlert('此栏目下面有文章或子栏目，无法删除！', '提示');
                            } else {
                                OutMessageBox("删除失败，未知问题！", 3000);
                            }
                        }
                    });
                }
            });
        }
        function OrderAjax(newid, oldid) {
            $.ajax({
                type: "get",
                url: "admin/website/catalog/catalogSorting", ////////排序方法
                data: {"newOrdId": newid, "oldOrdId": oldid},
                success: function (result) {
                    if (result.success) {
                        FListajax("${parentId}");	 //移动成功！刷新
                        OutMessageBox("移动成功！", 3000);
                    } else {
                        OutMessageBox("排序失败，未知原因!", 3000);
                    }
                }
            });
        }
    </script>
    <div>
        <div id="topnav" style="background-color: #E3E7EA;"><span
                style="color:#40919E;font-size:12px;margin-left: 5px">${cataNav}</span></div>
        <div style="margin-top:10px;margin-left:20px;margin-bottom:5px">
            <a href="javascript:addOrUpdateCata('${parentId}',false)">
                <button class="btn btn-info btn-xs">新增</button>
            </a>
        </div>
        <table width="97%" border="1" cellspacing="0" cellpadding="0">
            <thead>
            <tr style="background-color:#41a7c5;">
                <th style="text-align:center;">标识号</th>
                <th style="text-align:center;">栏目名称</th>
                <th style="text-align:center;">显示类型</th>
                <th style="text-align:center;">是否显示</th>
                <th style="text-align:center;">备注</th>
                <th style="text-align:center;">排序</th>
                <th style="text-align:center;">操作</th>
            </tr>
            </thead>
            <tbody style="background-color:#F7F7F9;word-break:break-all;">
            <%
                List<CatalogInfo> lists = (List<CatalogInfo>) request.getAttribute("subCatalogs");
                if (lists != null) {
                    for (int i = 0; i < lists.size(); i++) {
                        int lastOrderId = 0;  //设置排序的上一个位置
                        int nextOrderId = 0;  //设置排序的下一个位置
                        if (i == 0) {
                            lastOrderId = lists.get(i).getOrderId();
                            if (lists.size() - 1 == i) {
                                nextOrderId = lists.get(i).getOrderId();
                            } else {
                                nextOrderId = lists.get(i + 1).getOrderId();
                            }
                        } else {
                            lastOrderId = lists.get(i - 1).getOrderId();
                            if (lists.size() - 1 == i) {
                                nextOrderId = lists.get(i).getOrderId();
                            } else {
                                nextOrderId = lists.get(i + 1).getOrderId();
                            }
                        }
            %>
            <tr onmouseover="this.style.backgroundColor='#BCD8E0'" onmouseout="this.style.backgroundColor='#F7F7F9'">
                <td width="140px" style="text-align:center;" title="<%=lists.get(i).getCataCode()%>"><%=CharUtil
                        .subStringByte(lists.get(i).getCataCode(), 15) %><input type="hidden"
                                                                                value="<%=lists.get(i).getId()%>"/></td>
                <td width="120px" title="<%=lists.get(i).getName()%>"><%=CharUtil
                        .subStringByte(lists.get(i).getName(), 16) %>
                </td>
                <td width="115px" style="text-align: center">
                    <%
                        switch (lists.get(i).getShowType().charAt(0)) {
                            case 'A':
                    %>
                    文章列表
                    <%
                            break;
                        case 'H':
                    %>
                    图片横排
                    <%
                            break;
                        case 'V':
                    %>
                    图片纵排
                    <%
                            break;
                        case 'S':
                    %>
                    静态页面
                    <%
                            break;
                        case 'O':
                    %>
                    其他类型
                    <%
                            break;
                        default:
                    %>
                    未知类型
                    <%
                                break;
                        }
                    %>
                </td>
                <td width="100px" style="text-align: center">
                    <%
                        switch (lists.get(i).getIsShow().charAt(0)) {
                            case 'Y':
                    %>
                    显示
                    <%
                            break;
                        case 'N':
                    %>
                    不显示
                    <%
                            break;
                        default:
                    %>
                    未知
                    <%
                        }
                    %>
                </td>
                <td width="160px" title="<%=lists.get(i).getRemark()%>"><%=CharUtil
                        .subStringByte(lists.get(i).getRemark(), 24) %>
                </td>
                <td width="80px" style="text-align: center">
                    <a href="#" onclick="OrderAjax('<%=lastOrderId %>','<%=lists.get(i).getOrderId() %>')"><span
                            class="glyphicon glyphicon-triangle-top" aria-hidden="true"></span></a>&nbsp;
                    <a href="#" onclick="OrderAjax('<%=nextOrderId%>','<%=lists.get(i).getOrderId() %>')"><span
                            class="glyphicon glyphicon-triangle-bottom" aria-hidden="true"></span></a>
                </td>
                <td width="150px" style="text-align: center">&nbsp;&nbsp;
                    <a href="javascript:addOrUpdateCata('<%=lists.get(i).getId()%>',true)">修改</a>
                    &nbsp;&nbsp;&nbsp;
                    <a href='javascript:deleteCatalog("<%=lists.get(i).getId()%>")'>删除</a>
                </td>
            </tr>
            <%
                }
            } else {
            %>
            <tr height="40px">
                <td colspan="6" align="center"><span style="color:red;font-size:20px">没有相关栏目！</span></td>
            </tr>
            <%
                }
            %>
            </tbody>
        </table>
    </div>
</div>


